﻿/*************************************************
 * 
 *  框架执行基础通用类
 * 
 *  create by ternence
 * 
 *  create datetime at 2017-03-17
 *  
 *  西安佳卓信息科技有限公司 ©2017
 * 
 * ***********************************************/


/*
 * 时间戳转换为时间
 */
function DataIntToDate(nowdate) {
    var now = new Date(nowdate * 1000);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    return formatDate((year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second), "yyyy-MM-dd hh:mm:ss");
}

/*
 * 刷新当前页面
 */
function Replace() {
    location.reload();
    return false;
}

/*
 * 禁止/允许弹出层弹出
 */
function Allow(isNo) {
    if (isNo)
        $("#test").attr("ID", "myModal");   //修改弹出div的ID，使之弹出
    else
        $("#myModal").attr("ID", "test");   //修改弹出div的ID，使之不弹出
}

/*
 * 自动获取页面控件值
 */
function GetWebControls(element,jq) {
    var reVal = "";
    var $ = jq;
    $(element).find('input,select,textarea').each(function (r) {
        var id = $(this).attr('id');
        var value = $(this).val();
        var type = $(this).attr('type');
        switch (type) {
            case "checkbox":
                if ($(this).attr("checked")) {
                    reVal += '"' + id + '"' + ':' + '"1",'
                } else {
                    reVal += '"' + id + '"' + ':' + '"0",'
                }
                break;
            default:
                if (value == "") {
                    value = "";
                }
                reVal += '"' + id + '"' + ':' + '"' + $.trim(value) + '",'
                break;
        }
    });
    reVal = reVal.substr(0, reVal.length - 1);
    return jq.parseJSON('{' + reVal + '}');
}

/*
 * 自动给控件赋值
 */
function SetWebControls(data) {
    for (var key in data) {
        var id = $('#' + key);
        var value = $.trim(data[key]).replace("&nbsp;", "");
        var type = id.attr('type');
        switch (type) {
            case "checkbox":
                if (value == 1) {
                    id.attr("checked", 'checked');
                } else {
                    id.removeAttr("checked");
                }
                $('input').customInput();
                break;
            default:
                id.val(value);
                break;
        }
    }
}


/**
 * 获取选中复选框值(数组)
 **/
function CheckboxValueIDs(div,jq) {
    var $ = jq;
    var chk_value = [];
    $('#' + div + ' input[name="chk"]:checked').each(function () {
        chk_value.push($(this).val());
    });
    return chk_value;
}

/**
 * 获取复选单元格数据
 **/
function CheckboxValueByTrNames() {
    var chk_value = [];
    $('input[name="chk"]:checked').each(function () {
        var tr = $(this);
        var tds = tr.find("td");
        tds.each(function () {
            var td = $(this);
            var name = tablerow.find("[name='type']").val();
            chk_value.push(name);
        });
    });
    return chk_value;
}

